package everyday;

import org.junit.jupiter.api.Test;

/**
 * switch操作
 *
 * @author gaojie
 * @date 2022-11-24
 */
public class SwitchOperation {

    @Test
    void testNull() {
       testNull("1");
       testNull("2");
       testNull(null);
    }

    /**
     * 测试 switch 遇到 null 会不会报错
     * 结果证明：switch 遇到 null 属性会报空指针
     */
    private void testNull(String name) {
        switch (name) {
            case "1":
                System.out.println("1111");
                break;
            case "2":
                System.out.println("2222");
                break;
            default:
                System.out.println("default");
        }
    }

}
